#ifndef PAINTAREA_H
#define PAINTAREA_H

#include <QWidget>
#include <QLabel>
#include <QDebug>
#include <QPixmap>
#include <QMouseEvent>
#include <opencv2/opencv.hpp>
#include <vector>
#include "status.h"

class PaintArea : public QLabel
{
public:
    PaintArea(QWidget *parent, Status *p);

    void setPStatus(Status *p)
    {
        pStatus = p;
    }

    void setIsSaved(bool b)
    {
        isSaved = b;
    }

    bool getIsSaved()
    {
        return isSaved;
    }

    void setScale(double newScale)
    {
        scale = newScale;
    }

    double getScale(void)
    {
        return scale;
    }

    // 设置屏幕坐标(0, 0)对应的图像像素坐标(x, y)
    void setStartImagePixel(const cv::Point p)
    {
        startImagePixel = p;
    }
    // 得到当前屏幕坐标对应的图像像素坐标
    const cv::Point& getStartImagePixel() const
    {
        return startImagePixel;
    }

    bool getCanDraw()
    {
        return canDraw;
    }

    void setCanDraw(const bool _canDraw)
    {
        canDraw = _canDraw;
    }

protected:
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);

private:
    //　一些事件响应处理函数
    // 重写绘制事件响应函数
    void paintEvent(QPaintEvent *event);
    // 显示标注项
    void showAnnotation(ImageAnnItem &polyData);
    // 鼠标左键弹起事件
    void lButtonUpEvent(cv::Point p);
    //鼠标左键移动事件
    void lButtonMoveEvent(cv::Point p);
    // 鼠标左键按下事件
    void lButtonDownEvent(cv::Point p);
    // 鼠标右键弹起事件
    void rButtonUpEvent(cv::Point p);
    // 鼠标右键按下事件
    void mButtonUpEvent(cv::Point);
    // 找到points中与curP相邻的点
    vector<cv::Point>::iterator findPoint(vector<cv::Point> &points, cv::Point curP);

    Status *pStatus = nullptr;
    QImage img;
    // 缩放系数
    double scale = 1.0;
    // 图像缩放时的插值方法，默认为线性插值
    int interpStyle = cv::INTER_LINEAR;
    // 屏幕坐标(0, 0)对应的图像像素坐标(x, y)
    cv::Point startImagePixel;
    // 标记图片修改是否被保存
    bool isSaved = true;
    // 标记是否已经添加了标注项
    bool canDraw = false;
};


#endif // PAINTAREA_H
